<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Title</title>
</head>
<body>
	<script>
		let arr = ['1','20','-5','3'];
		console.log(arr);
		let newArr = arr.map(function (s) {
			return parseInt(s);
		})
		console.log('新数组：'+newArr);   //新数组：1,20,-5,3
		let newArr2 = arr.map(s => parseInt(s))
		console.log('箭头函数新数组：'+newArr2);  //箭头函数新数组：1,20,-5,3

		//reduce
		let arr1 = [1,20,-5,3];
		let result1 = arr1.reduce(function (a, b) {
			console.log(a, b)
			//注释【return a + b】结果：
			//1 20
			//undefined -5
			//undefined 3

			return a + b
			//下一轮的a为前一轮的返回值
			//1 20
			//21 -5
			//16 3
			//累加操作
		})
		console.log(result1)
		let result2 = arr1.reduce((a, b) => a + b)
		console.log(result2)
		let result3 = arr1.reduce((a, b) => a * b)
		console.log(result3)
		let result4 = arr1.reduce(function (a, b) {
			//0 1
			//0 20
			//0 -5
			console.log(a, b)
			return a * b
		}, 0)
		//0表示可选初始值
		console.log(result4)     //-0 就是0
		let result5 = arr1.reduce((a, b) => a + b, 0)
	</script>
</body>
</html>